<?php

namespace App\Http\Controllers\Admin\RedEnvelope;

use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;    //引用http请求类
use App\Response\Response;

class RedEnvelopeRecordController extends BaseController {

    /**
     * @api {get} /red-envelope/record 游戏记录
     * @apiVersion 0.1.0
     * @apiName 全服红包-游戏记录
     * @apiGroup 全服红包
     *
     * @apiParam {string} start_date 开始日期 可选
     * @apiParam {string} end_date 结束日期 可选
     * @apiParam {number} serial  期数 可选
     * @apiParam {number} page 当前页数 可选
     * @apiParam {number} perPage 分页容量 可选
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
    {
    "code": 200,
    "data": {
        "list": [
        {
            "id(期数)": 515,
            "rule_type(接龙规则 规则类型，1：最低接龙  2：最高接龙)": 1,
            "base_money(保证金)": "999.00",
            "reward_count(糖果数)": 999,
            "join_user_count(参与游戏人数)": 2,
            "user_count_limit(可容纳用户总数)": 2,
            "status(状态 此轮游戏的状态 1：正常结束 2：未开始，被强制中断 3：未开始，保存参与用户信息，下次重用 4: 正在进行\r\n 5：异常中断)": 1,
            "start_time(开始时间)": "2020-10-22 01:26:00",
            "end_time(结束时间)": "2020-10-22 15:06:59"
        }
    ],
    "meta": {
            "page": 1,
            "limit": 10,
            "next": null,
            "total": 1
        }
    }
    }
     *
     *
     */
    public function list(Request $request) {
        //参数校验
        $v = app('validator')->make($request->all(),
            [
                'start_date' => 'filled|string|date_format:Y-m-d',
                'end_date' => 'filled|string|date_format:Y-m-d',
                'serial' => 'filled|numeric',
                'perPage' => 'filled|numeric',
                'page' => 'filled|numeric',
            ]);
        if ($v->fails()) throw new BasicException(10001, $v->errors()->first());

        $params = $request->input();
        if (!empty($params['end_date'])) {
            $params['end_date'] = $params['end_date'] . " 23:59:59";
        }

        $list = app('repo_red_envelope')->getRoomLogQueryList($params);

        return Response::sendList($list);
    }


    /**
     * @api {get} /red-envelope/record/detail 游戏记录详情
     * @apiVersion 0.1.0
     * @apiName 全服红包-游戏记录详情
     * @apiGroup 全服红包
     *
     * @apiParam {number} serial  期数 必穿
     *
     *
     * @apiSuccessExample 成功响应
     *
     *
    {
        "code": 200,
        "data": [
        {
            "reward_count(获得糖果)": 74,
            "nickname(用户昵称)": "啊吧啊吧啊吧啊吧啊b",
            "user_code(用户id)": 617040
        }
       ]
    }
     *
     *
     */
    public function detail(Request $request) {
        //参数校验
        try {
            $this->validate($request, [
                'serial' => 'required|numeric',
            ]);
        } catch (\Exception $e) {
            throw new BasicException(10001, json_encode($e->errors()));
        }
        $params = $request->input();

        $list = app('repo_red_envelope')->userLogRecord($params['serial']);

        return Response::sendData($list);
    }
}
